package com.ruoyi.supermarket.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.supermarket.domain.RkVo;
import com.ruoyi.supermarket.domain.Vo.ShCx;
import com.ruoyi.supermarket.domain.Xqpurchase;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supermarket.domain.Purchase;
import com.ruoyi.supermarket.service.IPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购采退汇总Controller
 * 
 * @author ruoyi
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/supermarket/purchase")
public class PurchaseController extends BaseController
{
    @Autowired
    private IPurchaseService purchaseService;

    /**
     * 查询采购采退汇总列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('supermarket:purchase:list')")
    @GetMapping("/cSlist")
    public TableDataInfo cSlist(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchasecSList(purchase);
        return getDataTable(list);
    }
    /**
     * 查询采购采退汇总列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:list')")
    @GetMapping("/listTwo")
    public TableDataInfo listTwo(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseListTwo(purchase);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:list')")
    @GetMapping("/listThree")
    public TableDataInfo listThree(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseListThree(purchase);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('supermarket:purchase:list')")
    @GetMapping("/listPurchaseZf")
    public TableDataInfo listPurchaseZf(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseListZf(purchase);
        return getDataTable(list);
    }
    /**
     * 导出采购采退汇总列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:export')")
    @Log(title = "采购采退汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Purchase purchase)
    {
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        ExcelUtil<Purchase> util = new ExcelUtil<Purchase>(Purchase.class);
        util.exportExcel(response, list, "采购采退汇总数据");
    }

    /**
     * 获取采购采退汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return success(purchaseService.selectPurchaseByPurchaseId(purchaseId));
    }

    /**
     * 新增采购采退汇总
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:add')")
    @Log(title = "采购采退汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.insertPurchase(purchase));
    }

    /**
     * 采购反审核
     */
//    @PreAuthorize("@ss.hasPermi('supermarket:purchase:edit')")
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:fsh')")
    @Log(title = "采购采退汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.updatePurchase(purchase));
    }

    /**
     * 删除采购采退汇总
     */
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:remove')")
    @Log(title = "采购采退汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseIds)
    {
        return toAjax(purchaseService.deletePurchaseByPurchaseIds(purchaseIds));
    }

    //审核
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:audit')")
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody ShCx shCx)
    {
        return purchaseService.audit(shCx);
    }


    /**
     * 入库
     */
    @Log(title = "入库")
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:rk')")
    @PostMapping("/rk")
    public AjaxResult rk(@RequestBody RkVo rkVo)
    {
        return purchaseService.cgrk(rkVo);
    }


    /**
     * 出库
     */
    @Log(title = "出库")
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:outStore')")
    @GetMapping("/outStore/{purchaseId}")
    public AjaxResult outStore(@PathVariable Long purchaseId)
    {
        return purchaseService.outStore(purchaseId);
    }

    /**
     * 付款单制成
     */
    @GetMapping("/pay/{ids}")
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:pay')")
    public AjaxResult pay(@PathVariable List<Long> ids){
        return purchaseService.pay(ids);
    }

    //作废
    @GetMapping("/zfPurchase/{id}")
    @PreAuthorize("@ss.hasPermi('supermarket:purchase:zfPurchase')")
    public AjaxResult zfPurchasepay(@PathVariable Long id){
        return purchaseService.zfPurchasepay(id);
    }

}
